package top.stmo.springMVC.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.stmo.springMVC.pojo.User;

import java.util.ArrayList;
import java.util.List;


/**
 *          响应
 */
@Controller
public class ZooController {

    //响应页面
    @RequestMapping("/save1")
    public String save1() {
        return "index.jsp";
    }

    //响应文本数据
    @ResponseBody
    @RequestMapping("/save2")
    public String save2() {
        return "indextttjsp";
    }

    //响应pojo Json 数据
    @ResponseBody
    @RequestMapping("/save3")
    public User save3() {
        User user = new User();
        user.setName("张三");
        user.setAge(26);
        return user;
    }

    //响应集合 Json 数据
    @ResponseBody
    @RequestMapping("/save4")
    public List<User> save4() {
        List<User> users = new ArrayList<>();

        User user1 = new User();
        user1.setName("张三");
        user1.setAge(23);

        User user2 = new User();
        user2.setName("李四");
        user2.setAge(24);
        users.add(user1);
        users.add(user2);

        return users;
    }

}
